reducing string length using if condition in php